package com.seguriapp.social;

import android.content.Intent;
import android.text.Html;

public final class SharingHelper {

	/**
	 * 7 string parameters (%s). Replace the %s with values using
	 * String.format() 1 = Title 2 = Authors 3 and 4 = Link source and link mask
	 * 5 = Message ending 6 and 7 = App link and link mask
	 */
	public static final String EVENT_AND_ARTICLE_TEMPLATE = "<p><font size=22><b>%s</b></font><br/>%s<br/><a href='%s'>%s</a></p><br/><br/><br/><p>%s<br/><a href='%s'>%s</a></p>";
	/**
	 * 6 string parameters (%s). Replace the %s with values using
	 * String.format() 1 = Title 2 and 3 = Link source and link mask 4 = Message
	 * ending 5 and 6 = App link and link mask
	 */
	public static final String FEED_TEMPLATE = "<p><font size=22><b>%s</b></font><br/><a href='%s'>%s</a></p><br/><br/><br/><p>%s<br/><a href='%s'>%s</a></p>";
	// This type supports html and reduce the number of options to email
	// applications in the chooser.
	private static final String EMAIL_TYPE = "message/rfc822";

	private SharingHelper() {
	}

	/**
	 * 
	 * @param title
	 *            Chooser dialog title
	 * @param subject
	 *            Email subject
	 * @param htmlContent
	 *            Use {@link #EVENT_AND_ARTICLE_TEMPLATE},
	 *            {@link #FEED_TEMPLATE} or a custom html formatted string.
	 * @return Intent the intent to launch an intent chooser
	 */
	public static Intent shareEmailChooser(final String title,
			final String[] toEmail, final String subject,
			final String htmlContent) {
		final Intent intent = new Intent(Intent.ACTION_SEND);
		intent.setType(EMAIL_TYPE);
		if (toEmail != null) {
			intent.putExtra(Intent.EXTRA_EMAIL, toEmail);
		}
		intent.putExtra(Intent.EXTRA_SUBJECT, subject);
		if (htmlContent != null) {
			intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(htmlContent));
		}
		return Intent.createChooser(intent, title);
	}
}
